<template>
<Modal v-model="modalCreate"  @on-ok="handleModalCreateOK" :styles="{top: '30px'}" width="600">
	<template #header>添加自然人信息</template>
	<Form ref="form" :model="formData" :rules="ruleValidate" :label-width="90">
		<FormItem label="身份证" prop="person_card">
			<Upload ref="upload1" :show-upload-list="false" :on-success="handleUpload2Success" 
			:format="['jpg','jpeg','png']" :max-size="20480" type="drag" 
			name="file" style="display: inline-block;width:90px;"  
			:action="uploadActionPerson">
			    <div style="width: 90px;height:64px;line-height: 64px;">
			        <Icon type="ios-camera" size="24" v-if="formData.person_card==''"></Icon>
			        <img :src="formData.person_card" height="64" v-else>
			    </div>
			</Upload>
		</FormItem>
		<FormItem label="姓名" prop="person_name">
			<Input v-model="formData.person_name"></Input>
		</FormItem>
		<FormItem label="联系电话" prop="person_phone">
			<Input v-model="formData.person_phone"></Input>
		</FormItem>
		<FormItem label="性别" prop="person_gender">
			<Input v-model="formData.person_gender"></Input>
		</FormItem>
		<FormItem label="身份证号" prop="person_id">
			<Input v-model="formData.person_id"></Input>
		</FormItem>
		<FormItem label="出生年月" prop="person_birth">
			<Input v-model="formData.person_birth"></Input>
		</FormItem>
		<FormItem label="住址" prop="person_address">
			<Input v-model="formData.person_address"></Input>
		</FormItem>
	</Form>
	<template #footer><Button type="primary" @click="handleModalCreateOK">确定</Button></template>
</Modal>
</template>

<script>
import config from '@/config'
export default{
	data(){
		return{
			modalCreate:false,
			formData:{
				person_card:''
			},
			ruleValidate:{
				person_name: [{ required: true, message: '姓名不能为空'}],
				person_phone: [{ required: true, message: '联系电话不能为空'}],
				person_gender: [{ required: true, message: '性别不能为空'}],
				person_id: [{ required: true, message: '身份证号不能为空'}],
				person_birth: [{ required: true, message: '出生年月不能为空'}],
				person_address: [{ required: true, message: '住址不能为空'}],
			}
		}
	},
	props: {
		to: {
			type: String,
			default: ''
		}
	},
	computed:{
		uploadActionPerson(){
			return config.baseUrl+'tangyin/main/mainCase1UploadPerson.action'
		}
	},
	methods:{
		open(){
			this.modalCreate=true
			this.$refs.form.resetFields()
		},
		handleModalCreateOK(){
			this.$refs.form.validate((valid) => {
				if (valid) {
					let data=this.formData
					this.$axios.post("mainCase1PersonSave.action",data).then(res=>{
						this.$Message.success('保存成功')
						this.modalCreate=false
						this.$emit("loadData",data)
					})
				}
			})
		},
		handleUpload2Success(res, file, fileList){//身份证
			this.formData.person_card=config.baseUrl+res.tarFile
			this.formData.person_id=res.idNumber
			this.formData.person_name=res.name
			this.formData.person_address=res.address
			this.formData.person_birth=res.birthDate
			this.formData.person_gender=res.sex
		}
	}
}
</script>

<style>
</style>